<template>
  <el-form :inline="true" :model="form" class="demo-form-inline">
    <el-form-item label="合同标题">
      <el-input v-model="form.title" placeholder="合同标题" clearable />
    </el-form-item>

    <el-form-item label="对方单位">
      <el-input v-model="form.opposite_unit" placeholder="对方单位" clearable />
    </el-form-item>

    <el-form-item label="对方负责人">
      <el-input v-model="form.opposite_person_in_charge" placeholder="对方负责人" clearable />
    </el-form-item>

    <el-form-item label="经办人">
      <el-input v-model="form.agent" placeholder="经办人" clearable />
    </el-form-item>

    <el-form-item>
      <el-button type="primary" @click="GetShowinfo">查询</el-button>
    </el-form-item>
  </el-form>
  <el-table :data="Showinfo" border style="width: 100%">
    <el-table-column prop="title" label="合同标题" />
    <el-table-column prop="opposite_unit" label="对方单位" />
    <el-table-column prop="opposite_person_in_charge" label="对方负责人" />
    <el-table-column prop="signing_time" label="签订日期" />
    <el-table-column prop="agent" label="经办人" />
    <el-table-column prop="contract_category" label="合同类别" />

    <el-table-column prop="auditStatus" label="状态" v-slot="scope">
      <span v-if="scope.row.auditStatus == 0">待提交</span>
      <span v-if="scope.row.auditStatus == 1">待审批</span>
      <span v-if="scope.row.auditStatus == 2">已通过</span>
      <span v-if="scope.row.auditStatus == 3">已拒绝</span>
    </el-table-column>
    <el-table-column prop="fpeople" label="审批人" />

    <el-table-column label="操作" v-slot="scope">
      <el-button type="primary" @click="GetUpdateType(scope.row.id)">提交审批</el-button>
    </el-table-column>
  </el-table>
</template>

<script lang="ts" setup>
import { reactive, ref, onMounted } from 'vue'
import type { ComponentSize, FormInstance, FormRules } from 'element-plus'
import axios from 'axios'
import { ElMessage, ElMessageBox } from 'element-plus'

const form = reactive({
  title: '',
  opposite_unit: '',
  opposite_person_in_charge: '',
  agent: '',
  signing_time: '',
  PageIndex: 1,
  PageSize: 2,
  totalCount: '',
  pageCount: ''
})

const Showinfo = ref()
const GetShowinfo = () => {
  axios
    .get('/setpath/api/general_contracts/GetShowinfo', {
      params: {
        title: form.title,
        opposite_unit: form.opposite_unit,
        opposite_person_in_charge: form.opposite_person_in_charge,
        agent: form.agent,
        signing_time: form.signing_time,
        PageIndex: form.PageIndex,
        PageSize: form.PageSize
      }
    })
    .then((res) => {
      ; (Showinfo.value = res.data.data),
        (form.totalCount = res.data.totalCount),
        (form.pageCount = res.data.pageCount)
    })
}

const GetUpdateType = (id) => {
  ElMessageBox.confirm('您确定要提交吗', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  })
    .then(() => {
      axios.post('/setpath/api/general_contracts/Getsubmit?id=' + id).then((res) => {
        if (res.data > 0) {
          ElMessage.success('提交成功')
          GetShowinfo()
        } else {
          ElMessage.error('提交失败')
        }
      })
    })
    .catch(() => {
      ElMessage({
        type: 'info',
        message: 'Delete canceled'
      })
    })
}

onMounted(() => {
  GetShowinfo()
})
</script>
